package com.leanote.berial.tingphone.ui;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.leanote.berial.tingphone.R;
import com.leanote.berial.tingphone.adapter.CommonPagerAdapter;
import com.leanote.berial.tingphone.base.BaseActivity;

import java.util.ArrayList;

/**
 * 第一次启动应用时的广告页
 * <p/>
 * Created by berial on 15/7/28.
 */
public class GuideActivity extends BaseActivity implements ViewPager.OnPageChangeListener, View.OnClickListener {

	/**
	 * 立即体检按钮
	 */
	private View confirm;

	@Override
	public void initView() {
		setContentView(R.layout.activity_guide);

		ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);

		viewPager.setAdapter(new CommonPagerAdapter(getGuideImageArray()));

		viewPager.addOnPageChangeListener(this);

		confirm = findViewById(R.id.confirm);

		confirm.setOnClickListener(this);
	}

	/**
	 * 获得引导图的ImageView集合
	 */
	private ArrayList<ImageView> getGuideImageArray() {
		ArrayList<ImageView> imageViews = new ArrayList<>(4);
		for(int i = 0; i < 4; i++) {
			ImageView guideImageView = new ImageView(this);
			guideImageView.setScaleType(ImageView.ScaleType.FIT_XY);
			guideImageView.setImageResource(R.mipmap.guide_page1 + i);//添加4张引导图片
			imageViews.add(guideImageView);
		}
		return imageViews;
	}

	@Override
	public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}

	@Override
	public void onPageSelected(int position) {
		confirm.setClickable(position == 3);//当引导图为最后一页是按钮可点击
	}

	@Override
	public void onPageScrollStateChanged(int state) {}

	@Override
	public void onClick(View v) {
		startActivity(new Intent(this, MainActivity.class));
		finish();
	}
}
